﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Data;
using Meraz.Core.Model;
using Meraz.Core.Repositories;
using Ninject;

namespace Meraz.Core.Commands
{
    public interface IGetPostCommand
    {
        IPostRepository PostRepository { get; set; }
        Post Execute(string permalink);
        Post Execute(int postID);
    }

    /// <summary>
    /// Retrieves Post
    /// </summary>
    public class GetPostCommand : BaseCommand, IGetPostCommand
    {
        [Inject]
        public GetPostCommand(IPostRepository poRepo)
        {
            this.PostRepository = poRepo ?? new PostRepository();
        }
        public IPostRepository PostRepository { get; set; }
        public Post Execute(string permalink)
        {
            Post post = PostRepository.GetByPermalink(permalink);
            return post;
        }
        public Post Execute(int postID)
        {
            Post post = PostRepository.GetById(postID);
            return post;
        }
    }
}
